package summary;

/**
 * @Author: 海琳琦
 * @Date: 2022/3/10 21:59
 * https://leetcode-cn.com/problems/min-cost-climbing-stairs/
 */
public class Title746 {

    /**
     * dp[i]表示爬到低i层所花费最小费用
     * dp[i] = Math.min(dp[i-1]+cost[i-1],dp[i-2]+cost[i-2])
     * dp[0] = 0 dp[1] = 0
     * @param cost
     * @return
     */
    public static int minCostClimbingStairs(int[] cost) {
        int[] dp = new int[cost.length + 1];
        dp[0] = 0;
        dp[1] = 0;
        for (int i = 2; i < dp.length; i++) {
            dp[i] = Math.min(dp[i - 1] + cost[i - 1], dp[i - 2] + cost[i - 2]);
        }
        return dp[dp.length - 1];
    }

    public static void main(String[] args) {
        int[] cost = {10, 15, 20};
        minCostClimbingStairs(cost);
    }
}
